package home.ex.todolist.client.core;

import home.ex.todolist.shared.Todo;

import java.util.ArrayList;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;

public class MainTodoView extends ViewImpl implements MainTodoPresenter.MyView {
    
    private final Widget widget;
    
    @UiField
    FlexTable todolist;
    
    public interface Binder extends UiBinder<Widget, MainTodoView> {
    }
    
    @Inject
    public MainTodoView(final Binder binder) {
	this.todolist = new FlexTable();
	this.widget = binder.createAndBindUi(this);
    }
    
    @Override
    public Widget asWidget() {
	return this.widget;
    }
    
    @Override
    public void setTodolist(final FlexTable todolist) {
	this.todolist = todolist;
    }
    
    @Override
    public FlexTable getTodolist() {
	return this.todolist;
    }
    
    @Override
    public void setTodoData(final ArrayList<Todo> todoList) {
	if (todoList.size() > 0) {
	    for (int i = 0; i < todoList.size(); i++) {
		this.todolist.setWidget(i, 0, new CheckBox(todoList.get(i).getTodoName()));
	    }
	}
    }
}
